<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Remove Contact</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>
<h4>Select Contact to Remove from Group</h4>
<form action="#" method="post">
<select name="id">
<option value="n/a">Select a Contact's Name to Ungroup</option>
<?php
$conn=mysql_connect("localhost","root","") or die("Could not Establish Connection".mysql_error());
$db=mysql_select_db("contacts_ms",$conn) or die("No DB Selected".mysql_error());
$cqry=mysql_query("SELECT * FROM group_contacts ORDER BY group_name");
while($rw=mysql_fetch_array($cqry)){//This code selects the contact that the user wants to ungroup
?>
		<option value="<?php echo $rw['id'] ?>"> <?php echo $rw['group_name'].' '.$rw['phone'] ?></option> <?php
}
?>
</select><br/><br/>
<input type="submit" value="Remove from Group" name="submit" class="sbtns">&emsp;&emsp;&emsp;
<input type="reset" name="reset" value="Cancel" class="sbtns">
</form>
<?php
if(isset($_POST['submit'])){
	$id=$_POST['id'];
	//This code now delete the grouping field of the contact.
	$dqry=mysql_query("DELETE FROM group_contacts WHERE id='$id' ");
	if(!$dqry) $er="Could not Ungroup contact";
	else $er="Successfully Ungrouped Selected Contact";
	echo $er;
}
?>
</body>
</html>